﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Data;
using eProject.Model;
using eProject.ViewModel;

namespace eProject.View
{
    /// <summary>
    /// Interaction logic for CreateScheduleItemDialog.xaml
    /// </summary>
    public partial class CreateScheduleItemDialog
    {
        public CreateScheduleItemDialog(CommonManager manager)
        {
            InitializeComponent();
            DataContext = this;
            emplsListBox.DataContext = manager.Employees;
            fromDateTime.Value = DateTime.Now.Date;
            toDateTime.Value = DateTime.Now.Date.AddDays(1);
            ManHours = 0;
        }

        private void fromDateTime_ValueChanged(object sender, EventArgs e)
        {
            var from = fromDateTime.Value;
            var to = toDateTime.Value;

            if (to <= from)
            {
                toDateTime.Value = from.AddDays(1);
            }
        }

        public double ManHours { get; set; }

        public Period Period { get; set; }

        public IEnumerable<EmployeeViewModel> Employees{ get; private set;}

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Period = new Period(fromDateTime.Value.Date, toDateTime.Value.Date);
            DialogResult = true;
            Employees = emplsListBox.SelectedItems.Cast<EmployeeViewModel>();
        }

        
    }
    
    public class InverseBooleanConverter : IValueConverter
    {
        public static readonly InverseBooleanConverter Instance = new InverseBooleanConverter();


        public object Convert(object value, Type targetType, object parameter,
            System.Globalization.CultureInfo culture)
        {
            return !(bool?)value;
        }

        public object ConvertBack(object value, Type targetType, object parameter,
            System.Globalization.CultureInfo culture)
        {
            return !(bool?)value;
        }
    }

}
